from typing import List
from fastapi import APIRouter, Query
from services.user import query_all_user, add_user, delete_user_by_name, update_user_by_name
from models.request_model import CreateUserRequest, UpDataUserRequest
from models.user import User_Pydantic

router = APIRouter()

@router.get("/user", response_model=List[User_Pydantic])
async def get_all_user(
        name: str = Query(None ,description="用户名"),
        role: str = Query(None, description="用户角色"),
        level: int = Query(None, description="用户等级"),
        from_place: str = Query(None, description="用户来源"),
):
   return await query_all_user(name, role, level, from_place)

@router.post("/user")
async def create_user(body: CreateUserRequest):
   return await add_user(body.name, body.user, body.password, body.role, body.from_place)

@router.delete("/user/{name}")
async def delete_user(name: str):
   return await delete_user_by_name(name)

@router.put("/user")
async def update_user(body: UpDataUserRequest):
   return await update_user_by_name(body.name, body.role, body.level, body.from_place, body.active)

